/**
 * 银行管理管理初始化
 */
var Bank = {
    id: "BankTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Bank.initColumn = function () {
    return [
			{field: 'selectItem', radio: true},
            {title: '主键id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '报表日期', field: 'revtime', visible: true, align: 'center', valign: 'middle',width:'150px',
                formatter:function(value,row,index){
                    return value.substring(0,10);
                }
            },
            {title: '名称', field: 'username', visible: true, align: 'center', valign: 'middle'},
            {title: '银行名称', field: 'bankName', visible: true, align: 'center', valign: 'middle'},
            {title: '银行类型', field: 'banktypeName', visible: true, align: 'center', valign: 'middle'},
            {title: '银行状态', field: 'statusName', visible: true, align: 'center', valign: 'middle'},
            {title: '余额', field: 'balance', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: '备注', field: 'rsemarks', visible: true, halign:'center', align: 'center', valign: 'middle'},

    ];
};

/**
 * 检查是否选中
 */
Bank.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Bank.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加银行管理
 */
Bank.openAddBank = function () {
    var index = layer.open({
        type: 2,
        title: '添加银行管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/bank/bank_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看银行管理详情
 */
Bank.openBankDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '银行管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/bank/bank_update/' + Bank.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除银行管理
 */
Bank.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/bank/delete", function (data) {
            Feng.success("删除成功!");
            Bank.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("bankId",this.seItem.id);
        ajax.start();
    }
};

Bank.resetSearch = function () {
    $("#platform").val("");
    $("#username").val("");
	 $("#banktype").val("");
	  $("#status").val("");
    $("#revDate").val("");
}

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Bank.formParams = function() {
    var queryData = {};
    queryData['platform'] = $("#platform").val();
    queryData['username'] = $("#username").val();
    queryData['banktype'] = $("#banktype").val();
    queryData['status'] = $("#status").val();
    queryData['revDate'] = $("#revDate").val();
    return queryData;
}


/**
 * 查询银行管理列表
 */
Bank.search = function () {
    Bank.table.refresh({query: Bank.formParams()});
    $("#BankSum").remove();
    $("#BankTable").after(  Bank.tatol()   )
};


/**
 * 添加期初余额
 */
Bank.openAddBalance = function () {
    var index = layer.open({
        type: 2,
        title: '添加银行期初余额',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/bank/bank_addBalance'
    });
    this.layerIndex = index;
};


Bank.tatol= function(){

    var tatol;
    var ajax = new $ax(Feng.ctxPath + "/bank/tatol", function (result) {
        tatol=result;
    }, function (result) {
        Feng.error("查询失败!" + result.responseJSON.message + "!");
    });
    ajax.setData(Bank.formParams());
    ajax.start();
    var rowTem = '<div><table id="BankSum" data-mobile-responsive="true" data-click-to-select="false" class="table table-hover table-striped" style="margin-top: -0px;color: #2A2E36;font-size: 14px;"><tbody id="BankSum" >'+
        '<tr data-index="0">'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">入款银行可用资金：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.incomeAvailable+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">入款银行冻结余额：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.incomeFreezing+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">入款银行总余额：</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.incomeBankTotal+'</td></tr>'+
        '<tr data-index="0">'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">中转银行可用资金：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.mindAvailable+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">中转银行冻结余额：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.mindFreezing+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">中转银行总余额：</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.mindBankTotal+'</td></tr>'+
        '<tr data-index="0">'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">出款银行可用资金：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.outAvailable+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">出款银行冻结余额：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.outFreezing+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">出款银行总余额：</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.outBankTotal+'</td></tr>'+
        '<tr data-index="0">'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">银行可用资金：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.available+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">银行冻结余额：</td> '+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.freezing+'</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 150px; ">银行总余额：</td>'+
        '<td style="text-align: right; vertical-align: middle; width: 200px; ">'+tatol.bankTotal+'</td></tr>'+
        '</tbody></table></div>';
    return rowTem;
}

/**
 * 打开导出页面
 */
Bank.operExport = function(){
    window.location.href = "/bank/exportbank?revtime=" + $("#revDate").val();
}

$(function () {
    var defaultColunms = Bank.initColumn();
    var table = new BSTable(Bank.id, "/bank/list", defaultColunms,Bank);
    table.setPaginationType("server");
    table.setQueryParams(Bank.formParams());
    Bank.table = table.init();
	//添加表头
	$(".fixed-table-toolbar").after("<div style='text-align: center;vertical-align: middle;font-size: 22px;color: #6979d7;font-weight: bold;'> 银行余额</div>");
    $("#BankTable").after(Bank.tatol());
});
